package com.service;

import com.dao.Accountdao;
import com.domain.Account;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.tool.TranseactionManger;

import javax.annotation.PostConstruct;
import javax.annotation.PreDestroy;
import java.util.List;
@Service("accountservice")
public class AccountserviceImpl implements Accountservice {
    @Autowired
private Accountdao accountdao;
    @Autowired
    private TranseactionManger transeactionManger;
    @Override
    public List<Account> saveAccount() {
        System.out.println("com/service");
        return accountdao.saveAccount();
    }

    @Override
    public Account findbyid(Integer id) {
            Account account=accountdao.findbyid(id);
            return account;
    }
    @Override
    public int update(Account account) {
        return accountdao.update(account);
    }

    @Override
    public int delete(Integer id) {
        return accountdao.delete(id);
    }
    @Override
    public int sace(Account account) {
        return accountdao.sace(account);
    }
    @Override
    public void tranfer(String name1,String name2,float money) {
            Account user1=accountdao.transfaer(name1);
        Account user2=accountdao.transfaer(name2);
        user1.setMoney(user1.getMoney()-money);
        user2.setMoney(user2.getMoney()+money);
            accountdao.update(user1);
            accountdao.update(user2);
    }
    @PostConstruct
    public void init(){
        System.out.println("开始");
    }
    @PreDestroy
    public void edn(){
        System.out.println("销毁");
    }
}
